package com.ckx.config.feign;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.*;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class FeignLife implements LoadBalancerLifecycle<RequestDataContext, ResponseData, ServiceInstance> {

    @Override
    public void onStart(Request<RequestDataContext> request) {
        log.info("onStart");
    }

    @Override
    public void onStartRequest(Request<RequestDataContext> request, Response<ServiceInstance> lbResponse) {
         log.info("context: {}, target server: {}", request.getContext(), lbResponse.getServer());
    }

    @Override
    public void onComplete(CompletionContext<ResponseData, ServiceInstance, RequestDataContext> completionContext) {
        log.info("completionContext: {}", completionContext.getClientResponse());
        MDC.clear();
    }


}
